package com.example.demo.com.example.adapter.thirdAdapter;

import com.example.demo.com.example.adapter.ReturnMsg;
import com.example.demo.com.example.adapter.SiginService;

public class PassportForThirdAdapter extends SiginService implements IPassportForThird {
    @Override
    public ReturnMsg loginForQQ(String id) {
        return processLogin(id,LoginForQQAdapter.class);
    }

    public ReturnMsg loginForWechat(String id){
        return processLogin(id,LoginForWechatAdapter.class);
    }

    private ReturnMsg processLogin(String key,Class<? extends LoginAdapter> clazz){
        try {
            LoginAdapter adapter = clazz.newInstance();
            if (adapter.support(adapter)) {
                return adapter.login(key, adapter);
            }else{
                return null;
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
